package com.caiyouxi.common.service;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

/**
 * User: weicy
 * Date: 2015/3/26 0026
 * Time: 下午 19:42
 */
public class BaseService {

    @Autowired
    public RedisService redisService;

    protected ResData success(Object data){
        return new ResData(ErrorCode.SUCCESS.getCode(),ErrorCode.SUCCESS.getMsg(),data);
    }

    protected ResData failed(String code,String msg,Object data){
        return new ResData(code,msg,data);
    }

    public ResData failed(ErrorCode code) {
        return new ResData(code.getCode(),code.getMsg(),null);
    }

    protected  ResData page_list(QueryParams pageBean){

        HashMap<String,Object> pages = new HashMap<String, Object>();
        pages.put("page",pageBean.getPage());
        pages.put("total",pageBean.getTotal());
        pages.put("list",pageBean.getList());
        return new ResData(ErrorCode.SUCCESS.getCode(),ErrorCode.SUCCESS.getMsg(),pages);
    }

}
